<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/homepages/css/main.css" type="text/css"></link>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.4.min.js"></script>
     <script type="text/javascript" src="${pageContext.request.contextPath}/homepages/js/forms.js"></script>
	<script type="text/javascript">
		var basePath = "/";
		$(function(){
			basePath = '${pageContext.request.contextPath}';
			$.ajax({
			   url: "${pageContext.request.contextPath}/sys/getUIColumns",
			   type:"post",
			   data: "dsid=${formType}",
			   success: function(columns){
			   	 var formTableObj = $('#formTable');
				 var tableHTML = "";
				 var lineCount = 0;
				 var lineCol = 4;
				 var rootCount = [];
				 var columnIdTmp = "";
				     for(var i = 0; i < columns.length; i++){
				        if(lineCount % lineCol == 0){
					     	tableHTML += "<tr>";
				     	}
				     	if(columns[i].parentGroup != null && columns[i].parentGroup != ''){
				        	if(lineCount % lineCol > 0){
					     			tableHTML += "<td colspan='"+((lineCol-lineCount % lineCol)*2)+"'></td>"
					     	}
					     	tableHTML += "</tr><tr>";
					     	tableHTML += "<td class='group_title' colspan='"+(lineCol*2)+"'>=="+columns[i].colnName+"==</td>";
					     	tableHTML += "</tr>";
					     	lineCount=0;
					     	continue;
				        }
				     	if(columns[i].show != 'F'){
				     		if(columns[i].singleRow == 'T'){
					     		if(lineCount % lineCol > 0){
					     			tableHTML += "<td colspan='"+((lineCol-lineCount % lineCol)*2)+"'></td>"
					     		}
					     		tableHTML += "</tr><tr>";
					     		tableHTML += "<td class='name_td'>"+columns[i].colnName+"</td><td class='input_td' colspan='"+(lineCol*2-1)+"'>";
					     		tableHTML += formatInputObj(columns[i]);
					     		tableHTML += "</td>";
					     		tableHTML += "</tr>";
					     		lineCount=0;
					     	}else{
					     		tableHTML += "<td class='name_td'>"+columns[i].colnName+"</td><td>";
					     		tableHTML += formatInputObj(columns[i]);
					     		tableHTML += "</td>";
					     		lineCount++;
					     		if(lineCount % lineCol == 0){
						     		tableHTML += "</tr>";
					     		}
					     	}
				     	}
				     }
			     formTableObj.html(tableHTML);
			   }
			});
			
		});
		
		function formatInputObj(clnObj){
			var inpHTML = "";
			var inpType = clnObj.inputType;
			var ediType = clnObj.ediType;
			var properName = "";
			if(clnObj.javaClass != null || clnObj.javaProperty != null || clnObj.javaClass != "" || clnObj.javaProperty != ""){
				if(clnObj.javaClass != null && clnObj.javaProperty != null && clnObj.javaClass != "" && clnObj.javaProperty != ""){
					properName = "name='"+clnObj.javaClass+"."+clnObj.javaProperty+"'"
				}
				if((clnObj.javaClass == null || clnObj.javaClass == "") && (clnObj.javaProperty != null || clnObj.javaProperty != "")){
					properName = "name='"+clnObj.javaProperty+"'"
				}
			}
			var openLoadSameStr = "";
			if(clnObj.openLoadSameStr == 'T' && clnObj.openLoadType != null 
				&& clnObj.openLoadType != "" && (inpType == 'input' || inpType == null || inpType == '')){
				//查找相似的数据
				//openLoadSameStr = "  onkeydown= if(event.keyCode==13)loadSameStr(this,'"+clnObj.openLoadType+"','"+basePath+"');";
			}
			var width = clnObj.width;
			if(width == 0){width = "width:100%;"}else{width="width:"+width+"px;"}
			var height = clnObj.height;
			if(height == 0){height = ""}else{height="height:"+height+"px;"}
			var javaClass = clnObj.javaClass;
			var readOnly = clnObj.readOnly;
			var properties = properName + " " + openLoadSameStr;
			//对象类型 char integer number date time datetime input
			// datalist select textarea
			//radio checkbox treelist email
			//link password file multivalue
			switch(inpType){
				
				case "select":
					inpHTML = "<select "+properties+" style='"+width+height+"'></select>";
					break;
				case "textarea":
					inpHTML = "<textarea "+properties+"></textarea>";
					break;
				case "datetime":
					inpHTML = "<input "+properties+" style='"+width+height+"' value='2013-01-01 10:10:00'/>";
					break;
				default:
					inpHTML = "<input "+properties+" style='"+width+height+"'/>";
			}
			return inpHTML;
		}
	</script>
</head>
<body>
	<h3 id="formTypeId">${formName }</h3>
	<div style="margin: 10px;">
		<c:forEach items="${buttons}" var="button">
			<c:if test="${button.scriptFunc == null || (button.scriptFunc == '')}" var="tf">
				<input type="button" value="${button.butnName}" />	
			</c:if>
			<c:if test="${!tf}">
				<input type="button" value="${button.butnName}" onclick="${button.scriptFunc}"/>	
			</c:if>
		</c:forEach>
	</div>
	<FORM ID="INFO_FORM" action="${pageContext.request.contextPath}/user/addUser" method="post">
		<table border="0" width="1080px;" cellpadding="0" cellspacing="0" class="table_border" id="formTable">
			<!-- 这里是动态的表单 -->
		</table>
	</FORM>
</body>
</html>
